<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/

namespace Admin\Controller;
use Think\Controller;
class AdController extends IndexController {
	
	//列表动作-----------------------------------------------------------------------------------------------
	public function indexAction(){
		
		$model=new \Admin\Model\AdModel();
		foreach($model->IndexGetData(
				//排序
				array(
					array('order'=>'id','name'=>'ID'),
					array('order'=>'subject','name'=>'名称'),
					array('order'=>'id','name'=>'标签'),
					array('order'=>'status','name'=>'状态')
				)
			) as $key=>$value){
			$this->assign($key,$value);
		}

		$this->display();
	}
	
	//添加动作-----------------------------------------------------------------------------------------------
	public function addAction(){
		
		if(IsPost('Submit')){
			$model=new \Admin\Model\AdModel();
			$result=$model->CreateData($model->FormatData());
			//if(!$result['id']){
				$upload=new \Upload\Model\FileModel();
				$upload->UseFile();
				$this->error($result['message'],U(MODULE_NAME.'/'.CONTROLLER_NAME.'/index/'),3);
				
			//}else{
				//$this->error($result['message'],U(MODULE_NAME.'/'.CONTROLLER_NAME.'/edit/id/'.$result['id']),3);
			//}
		}else{
			$this->display();
		}
		
	}

	//修改动作-----------------------------------------------------------------------------------------------
	public function editAction(){
		$id=I('get.id',0,'int');
		$model=new \Admin\Model\AdModel();
		$manage=$model->token(false)->where(" id=$id ")->find();
		if(!$manage['id']){
			$this->error('修改数据不存在!',U(MODULE_NAME.'/'.CONTROLLER_NAME.'/index'),3);
		}
			
		if(IsPost('Submit')){
			$result=$model->EditData($model->FormatData());
			$upload=new \Upload\Model\FileModel();
			$upload->UseFile();
			$this->error($result['message'],U(MODULE_NAME.'/'.CONTROLLER_NAME.'/edit/id/'.$id),3);
		}else{
			$this->assign('manage',$manage);
			$this->display('Ad:add');
		}
		
	}
	
	//删除动作-----------------------------------------------------------------------------------------------
	public function deleteAction(){
		$model=new \Admin\Model\AdModel();
		$result=$model->DeleteData();
		$this->error($result['message'],U(MODULE_NAME.'/'.CONTROLLER_NAME.'/index'),3);
	}
	
}